We also support tiles from the UK Ordnance Survey, currently only those which are freely available:
We also support some larger scale maps:
Finally, we suppose some tiles which are not open data, but may be available to you (e.g. if you work in a UK university). For obvious copyright reasons, examples are not shown below!
The data is released under Open Government Licence, Licence wording: "Contains OS data © Crown copyright and database right (2017)"
Tiles should be downloaded, the ZIP files expanded, and placed in a directory. We offer a simple initialisation step whereby a single directory needs to be given, and then all sub-directories are searched.
In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import tilemapbase
import os
datadir = os.path.join("..", "..", "..", "Data", "OS_OpenMap")
tilemapbase.ordnancesurvey.init(datadir)
In [2]:
# We have only downloaded and unzipped the files necessary for this notebook to run.
tilemapbase.ordnancesurvey.OpenMapLocal.found_tiles()
Out[2]:
In [3]:
tilemapbase.ordnancesurvey.VectorMapDistrict.found_tiles()
Out[3]:
In this example, we plot the University of Leeds campus, with the corner of the Geography building, the corner of the Gym, and the centre of the Arts library shown. (To be compared with e.g. Google Maps showing our projection is correct.)
In [4]:
ex = tilemapbase.ordnancesurvey.Extent.from_centre_lonlat(-1.55532, 53.80474, xsize=750)
source = tilemapbase.ordnancesurvey.OpenMapLocal()
plotter = tilemapbase.ordnancesurvey.Plotter(ex, source)
fig, ax = plt.subplots(figsize=(10,10))
plotter.plot(ax)
x, y = tilemapbase.ordnancesurvey.project(-1.55532, 53.80474)
x1, y1 = tilemapbase.ordnancesurvey.project(-1.553347, 53.807893)
x2, y2 = tilemapbase.ordnancesurvey.project(-1.552304, 53.804356)
ax.scatter([x, x1, x2], [y, y1, y2])
None
A much larger extent (which is rather slow to render...)
In [5]:
ex = tilemapbase.ordnancesurvey.Extent.from_centre_lonlat(-1.55532, 53.80474, xsize=10000)
plotter = tilemapbase.ordnancesurvey.Plotter(ex, source)
fig, ax = plt.subplots(figsize=(10,10))
plotter.plot(ax)
In [6]:
ex = tilemapbase.ordnancesurvey.Extent.from_centre_lonlat(-5.71808, 50.06942, xsize=750)
source = tilemapbase.ordnancesurvey.OpenMapLocal()
plotter = tilemapbase.ordnancesurvey.Plotter(ex, source)
fig, ax = plt.subplots(figsize=(10,10))
plotter.plot(ax)
x, y = tilemapbase.ordnancesurvey.project(-5.71808, 50.06942)
ax.scatter([x], [y])
None
In [7]:
ex = tilemapbase.ordnancesurvey.Extent.from_centre_lonlat(-3.02516, 58.64389, xsize=750)
source = tilemapbase.ordnancesurvey.OpenMapLocal()
plotter = tilemapbase.ordnancesurvey.Plotter(ex, source)
fig, ax = plt.subplots(figsize=(10,10))
plotter.plot(ax)
x, y = tilemapbase.ordnancesurvey.project(-3.02516, 58.64389)
ax.scatter([x], [y])
None
In [8]:
ex = tilemapbase.ordnancesurvey.Extent.from_centre_lonlat(-1.55532, 53.80474, xsize=750)
source = tilemapbase.ordnancesurvey.VectorMapDistrict()
plotter = tilemapbase.ordnancesurvey.Plotter(ex, source)
fig, ax = plt.subplots(figsize=(10,10))
plotter.plot(ax)
x, y = tilemapbase.ordnancesurvey.project(-1.55532, 53.80474)
x1, y1 = tilemapbase.ordnancesurvey.project(-1.553347, 53.807893)
x2, y2 = tilemapbase.ordnancesurvey.project(-1.552304, 53.804356)
ax.scatter([x, x1, x2], [y, y1, y2])
None
In [9]:
ex = tilemapbase.ordnancesurvey.Extent.from_centre_lonlat(-5.71808, 50.06942, xsize=750)
plotter = tilemapbase.ordnancesurvey.Plotter(ex, source)
fig, ax = plt.subplots(figsize=(10,10))
plotter.plot(ax)
x, y = tilemapbase.ordnancesurvey.project(-5.71808, 50.06942)
ax.scatter([x], [y])
None
In [10]:
ex = tilemapbase.ordnancesurvey.Extent.from_centre_lonlat(-3.02516, 58.64389, xsize=750)
plotter = tilemapbase.ordnancesurvey.Plotter(ex, source)
fig, ax = plt.subplots(figsize=(10,10))
plotter.plot(ax)
x, y = tilemapbase.ordnancesurvey.project(-3.02516, 58.64389)
ax.scatter([x], [y])
None
In [11]:
source = tilemapbase.ordnancesurvey.OpenMapLocal()
source = tilemapbase.ordnancesurvey.TileSplitter(source, 200)
x, y = tilemapbase.ordnancesurvey.project(-1.55532, 53.80474)
print(tilemapbase.ordnancesurvey.coords_to_os_national_grid(x, y))
source("SE 29383 34363")
Out[11]:
In [12]:
ex = tilemapbase.ordnancesurvey.Extent.from_centre_lonlat(-1.55532, 53.80474, xsize=750)
plotter = tilemapbase.ordnancesurvey.Plotter(ex, source)
fig, ax = plt.subplots(figsize=(10,10))
plotter.plot(ax)
x, y = tilemapbase.ordnancesurvey.project(-1.55532, 53.80474)
x1, y1 = tilemapbase.ordnancesurvey.project(-1.553347, 53.807893)
x2, y2 = tilemapbase.ordnancesurvey.project(-1.552304, 53.804356)
ax.scatter([x, x1, x2], [y, y1, y2])
None
In [13]:
source = tilemapbase.ordnancesurvey.TwoFiftyScale()
ex = tilemapbase.ordnancesurvey.Extent.from_centre_lonlat(-1.55532, 53.80474, xsize=15000)
plotter = tilemapbase.ordnancesurvey.Plotter(ex, source)
fig, ax = plt.subplots(figsize=(10,10))
plotter.plot(ax)
x, y = tilemapbase.ordnancesurvey.project(-1.55532, 53.80474)
x1, y1 = tilemapbase.ordnancesurvey.project(-1.553347, 53.807893)
x2, y2 = tilemapbase.ordnancesurvey.project(-1.552304, 53.804356)
ax.scatter([x, x1, x2], [y, y1, y2])
None
In [14]:
source = tilemapbase.ordnancesurvey.MiniScale()
source.filenames
Out[14]:
In [15]:
ex = tilemapbase.ordnancesurvey.Extent.from_centre_lonlat(-1.55532, 53.80474, xsize=75000)
plotter = tilemapbase.ordnancesurvey.Plotter(ex, source)
fig, ax = plt.subplots(figsize=(10,10))
plotter.plot(ax)
In [16]:
source_over = tilemapbase.ordnancesurvey.OverView()
print(source_over.filenames)
source_over.filename = 'GBOverviewPlus.tif'
source_over("SE 1 2")
Out[16]:
In [17]:
ex = tilemapbase.ordnancesurvey.Extent.from_centre_lonlat(-1.55532, 53.80474, xsize=250000)
plotter = tilemapbase.ordnancesurvey.Plotter(ex, source)
plotter_over = tilemapbase.ordnancesurvey.Plotter(ex, source_over)
fig, ax = plt.subplots(ncols=2, figsize=(18,9))
plotter_over.plot(ax[0])
plotter.plot(ax[1])
In [18]:
source = tilemapbase.ordnancesurvey.VectorMapDistrict()
scaled = tilemapbase.ordnancesurvey.TileScalar(source, 500)
scaled("SE 12345 65432")
Out[18]:
In [19]:
t5k_dir = None
tilemapbase.ordnancesurvey.TwentyFiveRaster.init(t5k_dir)
source = tilemapbase.ordnancesurvey.TwentyFiveRaster()
These are very detailed tiles, available (under my institution's subscription) as either 3200x3200 pixels or 1600x1600 pixel tiles. The data seems to be the same in either, but the 1600 sized tiles are re-rendered (and not just down-sized).
Unfortunately, PIL
seems, under my Windows build at least, to have a problem loading these tiles in TIF format: an odd red border replaces some of the image on the right and bottom. Converting the files to PNG format using some externel program works fine. YMMV.
In [20]:
mm_dir = None
tilemapbase.ordnancesurvey.MasterMap.init(mm_dir)
source = tilemapbase.ordnancesurvey.MasterMap()
In [21]:
# To use the smaller tiles
mm_dir = None # Must be a different directory
tilemapbase.ordnancesurvey.MasterMap.init(mm_dir)
source = tilemapbase.ordnancesurvey.MasterMap()
source.tilesize = 1600